home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 25
/
AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso
/
Updates
/
Hardware
/
FreeWheel
/
GUI.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-03-12
|
14KB
|
463 lines
#include <stdlib.h>
#include <string.h>
#include <exec/types.h>
#include <libraries/gadtools.h>
#include <intuition/GadgetClass.h>
#include <intuition/Screens.h>
#include <clib/gadtools_protos.h>
#include <clib/intuition_protos.h>
#include "GUI.h"
struct TextAttr GUI_DefaultFont = { "topaz.font", 8, 0, 0};
void GUI_Dispose(struct GUIContext *gui);
void GUI_Attach(struct GUIContext *gui,struct Window *win)
{
AddGList(win,gui->ContextGadget,0,-1,NULL);
RefreshGList(gui->ContextGadget,win,NULL,-1);
GT_RefreshWindow(win, NULL);
}
struct Gadget *GUI_BuildButton(struct GUIContext *gui,char *text,long id)
{
struct NewGadget newgad;
int topedge,leftedge,textwidth,gadgetheight;
if(gui->LastGadget)
{
textwidth=32+TextLength(&gui->Screen->RastPort,text,strlen(text));
topedge=gui->BorderTop+gui->InnerHeight;
leftedge=gui->BorderLeft+gui->InnerWidth/2-textwidth/2;
gadgetheight=gui->TextAttr->ta_YSize+6;
gui->InnerHeight+=8+gadgetheight;
newgad.ng_TextAttr = gui->TextAttr;
newgad.ng_VisualInfo = gui->VisualInfo;
newgad.ng_LeftEdge = leftedge;
newgad.ng_TopEdge = topedge;
newgad.ng_Width = textwidth;
newgad.ng_Height = gadgetheight;
newgad.ng_GadgetText = text;
newgad.ng_GadgetID = id;
newgad.ng_Flags = 0;
gui->LastGadget = CreateGadget(BUTTON_KIND, gui->LastGadget, &newgad,
GA_RelVerify,TRUE,
TAG_DONE);
gui->IDCMP|=BUTTONIDCMP;
}
return(gui->LastGadget);
}
struct Gadget *GUI_BuildWideButton(struct GUIContext *gui,char *text,long id)
{
struct NewGadget newgad;
int topedge,leftedge,textwidth,gadgetheight;
if(gui->LastGadget)
{
textwidth=16+TextLength(&gui->Screen->RastPort,text,strlen(text));
if(textwidth<(gui->InnerWidth-16))
textwidth=gui->InnerWidth-16;
else
gui->InnerWidth=textwidth+16;
topedge=gui->BorderTop+gui->InnerHeight;
leftedge=gui->BorderLeft+gui->InnerWidth/2-textwidth/2;
gadgetheight=gui->TextAttr->ta_YSize+6;
gui->InnerHeight+=8+gadgetheight;
newgad.ng_TextAttr = gui->TextAttr;
newgad.ng_VisualInfo = gui->VisualInfo;
newgad.ng_LeftEdge = leftedge;
newgad.ng_TopEdge = topedge;
newgad.ng_Width = textwidth;
newgad.ng_Height = gadgetheight;
newgad.ng_GadgetText = text;
newgad.ng_GadgetID = id;
newgad.ng_Flags = 0;
gui->LastGadget = CreateGadget(BUTTON_KIND, gui->LastGadget, &newgad,
GA_RelVerify,TRUE,
TAG_DONE);
gui->IDCMP|=BUTTONIDCMP;
}
return(gui->LastGadget);
}
struct Gadget *GUI_BuildText(struct GUIContext *gui,char *text)
{
struct NewGadget newgad;
int topedge,leftedge,textwidth,textwidth2,gadgetheight;
if(gui->LastGadget)
{
textwidth=32+TextLength(&gui->Screen->RastPort,text,strlen(text));
if(textwidth<(gui->InnerWidth-16))
textwidth=gui->InnerWidth-16;
else
gui->InnerWidth=textwidth+16;
topedge=gui->BorderTop+gui->InnerHeight;
leftedge=gui->BorderLeft+gui->InnerWidth/2-textwidth/2;
gadgetheight=gui->TextAttr->ta_YSize+6;
gui->InnerHeight+=gadgetheight+4;
newgad.ng_TextAttr = gui->TextAttr;
newgad.ng_VisualInfo = gui->VisualInfo;
newgad.ng_LeftEdge = leftedge;
newgad.ng_TopEdge = topedge;
newgad.ng_Width = textwidth;
newgad.ng_Height = gadgetheight;
newgad.ng_GadgetText = 0;
newgad.ng_GadgetID = 0;
newgad.ng_Flags = 0;
gui->LastGadget = CreateGadget(TEXT_KIND, gui->LastGadget, &newgad,
GTTX_Border,FALSE,
GTTX_Text,text,
GTTX_Justification,GTJ_CENTER,
GTTX_Clipped,TRUE,
TAG_DONE);
gui->IDCMP|=TEXTIDCMP;
}
return(gui->LastGadget);
}
struct Gadget *GUI_BuildCheckBox(struct GUIContext *gui,char *text,long id)
{
struct NewGadget newgad;
int topedge,leftedge,textwidth,guiwidth,gadgetwidth,gadgetheight;
textwidth=0;
if(gui->LastGadget)
{
gadgetwidth=gadgetheight=gui->TextAttr->ta_YSize+8;
if(text)
textwidth=8+TextLength(&gui->Screen->RastPort,text,strlen(text));
if(gui->TabStop>textwidth)
textwidth=gui->TabStop;
if(textwidth>(gui->InnerWidth-16))
gui->InnerWidth=textwidth+gadgetwidth+16;
guiwidth=gui->InnerWidth-16;
topedge=gui->BorderTop+gui->InnerHeight;
leftedge=8+gui->BorderLeft+textwidth;
gui->InnerHeight+=6+gadgetheight;
newgad.ng_TextAttr = gui->TextAttr;
newgad.ng_VisualInfo = gui->VisualInfo;
newgad.ng_LeftEdge = leftedge;
newgad.ng_TopEdge = topedge;
newgad.ng_Width = gadgetwidth;
newgad.ng_Height = gadgetheight;
newgad.ng_GadgetText = text;
newgad.ng_GadgetID = id;
newgad.ng_Flags = PLACETEXT_LEFT;
gui->LastGadget = CreateGadget(CHECKBOX_KIND, gui->LastGadget, &newgad,
GA_RelVerify,TRUE,
GTCB_Scaled,TRUE,
TAG_DONE);
gui->IDCMP|=CHECKBOXIDCMP;
}
return(gui->LastGadget);
}
struct Gadget *GUI_BuildSlider(struct GUIContext *gui,char *text,int min,int max,int level,long id)
{
struct NewGadget newgad;
int topedge,leftedge,textwidth,guiwidth,gadgetwidth,gadgetheight;
textwidth=0;
if(gui->LastGadget)
{
if(text)
textwidth=8+TextLength(&gui->Screen->RastPort,text,strlen(text));
if(gui->TabStop>textwidth)
textwidth=gui->TabStop;
if(textwidth>(gui->InnerWidth-16))
gui->InnerWidth=textwidth+100;
guiwidth=gui->InnerWidth-16;
gadgetwidth=guiwidth-textwidth;
topedge=gui->BorderTop+gui->InnerHeight;
leftedge=8+gui->BorderLeft+textwidth;
gadgetheight=gui->TextAttr->ta_YSize+8;
gui->InnerHeight+=6+gadgetheight;
newgad.ng_TextAttr = gui->TextAttr;
newgad.ng_VisualInfo = gui->VisualInfo;
newgad.ng_LeftEdge = leftedge;
newgad.ng_TopEdge = topedge;
newgad.ng_Width = gadgetwidth;
newgad.ng_Height = gadgetheight;
newgad.ng_GadgetText = text;
newgad.ng_GadgetID = id;
newgad.ng_Flags = PLACETEXT_LEFT;
gui->LastGadget = CreateGadget(SLIDER_KIND, gui->LastGadget, &newgad,
GA_RelVerify,TRUE,
GTSL_Min,min,
GTSL_Max,max,
GTSL_Level,level,
TAG_DONE);
gui->IDCMP|=SLIDERIDCMP;
}
return(gui->LastGadget);
}
struct Gadget *GUI_BuildSliderFormatted(struct GUIContext *gui,char *text,int min,int max,int level,long id)
{
struct NewGadget newgad;
int topedge,leftedge,textwidth,guiwidth,gadgetwidth,gadgetheight;
textwidth=0;
if(gui->LastGadget)
{
if(text)
textwidth=8+TextLength(&gui->Screen->RastPort,text,strlen(text));
if(gui->TabStop>textwidth)
textwidth=gui->TabStop;
if(textwidth>(gui->InnerWidth-16))
gui->InnerWidth=textwidth+100;
guiwidth=gui->InnerWidth-16;
gadgetwidth=guiwidth-textwidth;
topedge=gui->BorderTop+gui->InnerHeight;
leftedge=8+gui->BorderLeft+textwidth;
gadgetheight=gui->TextAttr->ta_YSize+8;
gui->InnerHeight+=6+gadgetheight;
newgad.ng_TextAttr = gui->TextAttr;
newgad.ng_VisualInfo = gui->VisualInfo;
newgad.ng_LeftEdge = leftedge;
newgad.ng_TopEdge = topedge;
newgad.ng_Width = gadgetwidth;
newgad.ng_Height = gadgetheight;
newgad.ng_GadgetText = NULL;
newgad.ng_GadgetID = id;
newgad.ng_Flags = PLACETEXT_LEFT;
gui->LastGadget = CreateGadget(SLIDER_KIND, gui->LastGadget, &newgad,
GA_RelVerify,TRUE,
GTSL_Min,min,
GTSL_Max,max,
GTSL_Level,level,
GTSL_LevelFormat,text,
GTSL_MaxLevelLen,strlen(text)+4,
TAG_DONE);
gui->IDCMP|=SLIDERIDCMP;
}
return(gui->LastGadget);
}
struct Gadget *GUI_BuildCycleGadget(str